<?php

namespace Rbac\Controller;
use Rbac\C\DataConverter;
use Rbac\C\Xpublic;
/**
 *  ReviewController
 * @author Jonas
 */
class ReviewController extends ExtendController {
   
   public function review(){
      $this->display();
   }
    /**
     * 显示数据
     */
    public function index() {
       $model = M('info_results');
       $rows = $model->group("title")->order('id')->select();
       foreach($rows as $key=>$v){
           $sql = "select count(tt.counts) counts from (SELECT count(*) as counts FROM `info_results` WHERE `title` = '".$v['title']."' GROUP BY name) as tt";
           $count = $model->query($sql);
           $v['count'] = $count[0]['counts'];
           $rows[$key] = $v;
       }
       $total = count($rows);
        if ($data["rows"] == null) {
            $data["rows"] = $rows;
        }
        $data['total'] = $total;
        //过滤数据
        $this->ajaxReturn($data);
    }
    
    /**
    *查看数据详细报表
    **/
    public function view(){
        //获取标题
        $title = $_POST['title'];
        //统计每个答案个数
        $sql = "SELECT title,results,count(*) as counts FROM `info_results` WHERE title='".$title."' group by `results`";
        $model = M('info_results');
        $result = $model->query($sql);
        $field = array();
        $data = array();
        foreach($result as $key=>$v){
            $field[] = $v['results'];
            $rows['value'] = $v['counts'];
            $rows['name'] = $v['results'];
            $data[] = $rows;
        }
        $this->ajaxReturn(array(
            "success"=>1,
            "data"=>array("field"=>$field,"data"=>$data)
        ));

    }
}
